//
//  YCAudioPlayer.m
//  MIDI
//
//  Created by 王禹丞 on 16/1/22.
//  Copyright © 2016年 QXSX. All rights reserved.
//

#import "YCAudioPlayer.h"

@implementation YCAudioPlayer

static id _instance ;

- (id)init{
    
    
    static id obj = nil;
    
    
   static dispatch_once_t onceToken;
  
    dispatch_once(&onceToken, ^{
        
        if ((obj = [super init]) != nil) {
            
            self.player = [[STKAudioPlayer alloc]init];
        }
    });
    
    self = obj;
    
    return self;
}


+ (instancetype)allocWithZone:(struct _NSZone *)zone{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        _instance =  [super allocWithZone:zone];
        
    });
    
    
    return _instance;
    
}


+ (instancetype)sharedYCAudioPlayer{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        _instance =  [[self alloc]init];
        
        
    });
    
    return _instance;
    
}

//-(void)configNowPlayingInfoCenter
//{
//    
//    if (self.nowPlayingMusicInfo == nil) {
//        return;
//    }
//    
//    
//    @autoreleasepool {
//        
//        NSDictionary *info = self.nowPlayingMusicInfo;
//        
//        
//        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
//        
//        //歌曲名称
//        [dict setObject:[info ObjectNullForKey:@"title"] forKey:MPMediaItemPropertyTitle];
//        
//        //演唱者
//        [dict setObject:[info ObjectNullForKey:@"author"] forKey:MPMediaItemPropertyArtist];
//        
//        //专辑名
//        //[dict setObject:[info ObjectNullForKey:@"album"] forKey:MPMediaItemPropertyAlbumTitle];
//        
//        //专辑缩略图
//        NSString *imagePath = [info ObjectNullForKey:@"thumb"];
//        imagePath = [NSString stringWithFormat:@"EGOImageLoader-%lu", (unsigned long)[[imagePath description] hash]];
//        NSString *imageLocalPath = [NSString stringWithFormat:@"%@/%@", EGOCacheDirectory(),imagePath];
//        
//        NSData * thumbData = [NSData dataWithContentsOfFile:imageLocalPath];
//        
//        if (thumbData != nil) {
//            UIImage *image = [UIImage imageWithData:thumbData];
//            MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc] initWithImage:image];
//            [dict setObject:artwork forKey:MPMediaItemPropertyArtwork];
//        }else
//        {
//            // FIXME: 无图的时候，读取图
//            
//        }
//        //音乐剩余时长
//        [dict setObject:[NSNumber numberWithDouble:self.audioPlayer.duration] forKey:MPMediaItemPropertyPlaybackDuration];
//        
//        //音乐当前播放时间 在计时器中修改
//        [dict setObject:[NSNumber numberWithDouble:self.audioPlayer.progress] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
//        
//        //设置锁屏状态下屏幕显示播放音乐信息
//        //DLog(@"显示播放音乐信息：%@\n%@",dict,[info ObjectNullForKey:@"title"]);
//        
//        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dict];
//        
//    }
//    
//}
//

/**
 *  响应远程音乐播放控制消息
 *
 *  @param receivedEvent
 */
//- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
//    
//    if (receivedEvent.type == UIEventTypeRemoteControl) {
//        
//        switch (receivedEvent.subtype) {
//                
//            case UIEventSubtypeRemoteControlPause:
//                //点击了暂停
//                [self pauseStreamer];
//                break;
//            case UIEventSubtypeRemoteControlNextTrack:
//                //点击了下一首
//                [self playNextMusic];
//                break;
//            case UIEventSubtypeRemoteControlPreviousTrack:
//                //点击了上一首
//                [self playPreMusic];
//                //此时需要更改歌曲信息
//                break;
//            case UIEventSubtypeRemoteControlPlay:
//                //点击了播放
//                [self pauseStreamer];
//                break;
//            default:
//                break;
//        }
//    }
//}

@end
